package com.by.goods.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.by.common.core.bean.ResultBean;
import com.by.common.core.response.R;
import com.by.goods.entity.Spu;
import com.by.goods.entity.SpuDetail;
import com.by.goods.service.SpuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "spu管理",description = "spu的增删改查")
@RestController
@RequestMapping("/api/v1")
public class SpuController {

    @Autowired
    SpuService spuService;


    @PostMapping("/spu")
    public ResultBean save(@RequestBody Spu spu){
        boolean rs= spuService.save(spu);
        return rs?R.success("保存成功"):R.fail("保存失败");
    }

    @GetMapping("querySpuList")
    public ResultBean querySpuList(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "4") int pageSize) {

        IPage<Spu> pageResult = spuService.querySpuList(pageNum, pageSize);
        return R.success("查询成功", pageResult);
    }

    @GetMapping("/spu/queryById")
    public ResultBean queryById(int spuId){
        SpuDetail spuDetail =spuService.queryById(spuId);
        return R.success("查询成功",spuDetail);
    }

    /*@GetMapping("/sku/queryDetail")
    public ResultBean queryDetail(@RequestParam(defaultValue = "1")int spuId, @RequestParam(defaultValue = "1")int skuId){
        Sku2 sku2 =skuService.query(spuId, skuId);
        return R.success("查询成功",sku2);
    }*/
}
